/* 储存采购管理相关store */

import { defineStore } from 'pinia';
import uniqueid from 'lodash.uniqueid';
import router from '@/router';

const useBuyStore = defineStore('BuyStore', {
  state: () => {
    return {
      currSupplierForm: {
        name: '',
        form: [],
      }, // 储存供应商暂存的模板
      CreateOrder: {},
      collect: [],
      productionToProcurement: [],
      msg: true,
      MaterialSummaryList: [],
      mustFormData: [
        {
          show: 1,
          componentType: 'NUMBER-UNIVERSAL',
          code: 'NUMBER-UNIVERSAL',
          props: { placeholder: '系统自动生成' },
          placeholder: '系统自动生成',
          name: '采购申请单号',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'number',
          values: [],
        },
        {
          show: 1,
          componentType: 'TEXT',
          code: 'TEXT',
          props: { placeholder: '请输入文字' },
          name: '采购申请名称',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'name',
          values: [],
        },
        {
          show: 1,
          componentType: 'CREATED_DY',
          code: 'CREATED_DY',
          props: { placeholder: '请输入文字' },
          name: '申请人',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'createBy',
          initialize: true,
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_DATE',
          code: 'APPLY_DATE',
          props: { placeholder: '请选择申请日期' },
          name: '申请日期',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'applyTime',
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_CAUSE',
          code: 'APPLY_CAUSE',
          props: { placeholder: '请输入文字' },
          name: '申请原因',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'description',
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_DEPT',
          code: 'APPLY_DEPT',
          props: { placeholder: '请输入文字' },
          name: '申请部门',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'deptId',
          initialize: true,
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_DETAILED',
          code: 'APPLY_DETAILED',
          props: {
            columns: [
              {
                title: '物料类型',
                dataIndex: 'materialName',
                slotName: 'materialName',
              },
              {
                title: '物料编码',
                dataIndex: 'number',
                slotName: 'number',
              },
              {
                title: '物料名称',
                dataIndex: 'name',
                slotName: 'name',
              },
              {
                title: '规格型号',
                dataIndex: 'spec',
                slotName: 'spec',
              },
              {
                title: '基本单位',
                dataIndex: 'basicName',
                slotName: 'basicName',
              },
              {
                title: '需求数量',
                dataIndex: 'amount',
                slotName: 'amount',
              },
              {
                title: '需求交付日期',
                dataIndex: 'deliveryTime',
                slotName: 'deliveryTime',
              },
              {
                title: '操作',
                dataIndex: 'optional',
                slotName: 'optional',
              },
            ],
            data: [
              {
                materialName: '',
                code: '',
                name: '',
                spec: '',
                purchaseUnitName: '',
                amount: '',
                deliveryTime: '',
              },
            ],
          },
          name: '申请明细',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          values: [],
        },
        {
          name: '附件',
          code: 'FILE',
          componentType: 'FILE',
          props: { data: [] },
          required: 2,
          span: 12,
          uuid: '17',
          show: 1,
          values: [],
          sort: 15,
          isMust: 1,
          isProcessConditions: 2,
          fieldName: '',
        },
      ],
      planFormData: [
        {
          show: 1,
          componentType: 'NUMBER-UNIVERSAL',
          code: 'NUMBER-UNIVERSAL',
          props: { placeholder: '系统自动生成' },
          placeholder: '系统自动生成',
          name: '采购计划单号',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'number',
          values: [],
        },
        {
          show: 1,
          componentType: 'TEXT',
          code: 'TEXT',
          props: { placeholder: '请输入文字' },
          name: '采购计划名称',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'name',
          values: [],
        },
        {
          show: 1,
          componentType: 'CREATED_DY',
          code: 'CREATED_DY',
          props: { placeholder: '请输入文字' },
          name: '创建人',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'createBy',
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_DATE',
          code: 'APPLY_DATE',
          props: { placeholder: '请输入文字' },
          name: '创建日期',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'createdAt',
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_CAUSE',
          code: 'APPLY_CAUSE',
          props: { placeholder: '请输入文字' },
          name: '采购原因',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'description',
          values: [],
        },
        {
          show: 1,
          componentType: 'APPLY_DEPT',
          code: 'APPLY_DEPT',
          props: { placeholder: '请输入文字' },
          name: '所属部门',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'deptId',
          values: [],
        },
        {
          show: 1,
          componentType: 'BUY-PLAN-DETAILS',
          code: 'BUY-PLAN-DETAILS',
          props: {
            columns: [
              {
                title: '物料编码',
                code: 'number',
              },
              {
                title: '物料名称',
                code: 'name',
              },
              {
                title: '规格型号',
                code: 'spec',
              },
              {
                title: '基本单位',
                code: 'basicName',
              },
              {
                title: '实际需求数量',
                code: 'actualAmount',
                slotName: 'actualAmount',
              },
              {
                title: '供应商名称',
                code: 'supplierName',
              },
              {
                title: '产品指导单价',
                code: 'guidePrice',
              },
              {
                title: '折扣',
                code: 'discount',
              },
              {
                title: '合计',
                code: 'totalPrice',
              },
            ],
            data: [],
          },
          name: '采购计划明细',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
        },
        {
          name: '附件',
          code: 'FILE',
          componentType: 'FILE',
          props: { data: [] },
          required: 2,
          span: 12,
          uuid: '17',
          show: 1,
          values: [],
          sort: 15,
          isMust: 1,
          isProcessConditions: 2,
          fieldName: '',
        },
      ],
      orderFormData: [
        {
          show: 1,
          componentType: 'NUMBER-UNIVERSAL',
          code: 'NUMBER-UNIVERSAL',
          props: { placeholder: '系统自动生成' },
          placeholder: '系统自动生成',
          name: '采购订单单号',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'number',
          values: [],
        },
        {
          show: 1,
          componentType: 'SUOOLIER-NAME',
          code: 'SUOOLIER-NAME',
          props: { placeholder: '请输入文字' },
          name: '供应商名称',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'supplierId',
          values: [],
        },
        {
          show: 1,
          componentType: 'CONTACT-NUMBER',
          code: 'CONTACT-NUMBER',
          props: { placeholder: '请输入文字' },
          name: '联系电话',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'phone',
          values: [],
        },
        {
          show: 1,
          componentType: 'BUYER',
          code: '"BUYER"',
          props: { placeholder: '请输入文字' },
          name: '采购员',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'salesman',
          values: [],
        },
        {
          show: 1,
          componentType: 'BUY-TOTAL-AMOUNT',
          code: 'BUY-TOTAL-AMOUNT',
          props: { placeholder: '请输入文字' },
          name: '采购总金额',
          required: 2,
          span: 12,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'totalPrice',
          values: [],
        },
        {
          show: 1,
          componentType: 'CONTRACT_SELECT',
          code: 'CONTRACT_SELECT',
          props: { placeholder: '请选择关联合同' },
          name: '关联合同',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'contractId',
          values: [],
        },
        {
          show: 1,
          componentType: 'BUY-DETAILED',
          code: 'BUY-DETAILED',
          props: {
            columns: [
              {
                title: '物料编码',
                dataIndex: 'number',
                slotName: 'number',
              },
              {
                title: '物料名称',
                dataIndex: 'name',
                slotName: 'name',
              },
              {
                title: '规格型号',
                dataIndex: 'spce',
                slotName: 'spce',
              },
              {
                title: '基本单位',
                code: 'basicUnitName',
              },
              {
                title: '物料指导单价',
                dataIndex: 'unitPrice',
                slotName: 'unitPrice',
              },
              {
                title: '折扣',
                dataIndex: 'discount',
                slotName: 'discount',
              },
              {
                title: '需求数量',
                dataIndex: 'amount',
                slotName: 'amount',
              },
              {
                title: '合计',
                dataIndex: 'total',
                slotName: 'total',
              },
              {
                title: '操作',
                dataIndex: 'operation',
                slotName: 'operation',
              },
            ],
            data: [
              {
                number: '',
                name: '',
                spce: '',
                unit: '',
                unitPrice: { money: '', unit: '' },
                discount: '',
                amount: '',
                total: { money: '', unit: '' },
              },
            ],
          },
          name: '采购明细',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'contractNumber',
          values: [],
        },
        {
          show: 1,
          componentType: 'DELIVERY_REQUIREMENTS_BC',
          code: 'DELIVERY_REQUIREMENTS_BC',
          props: {
            data: [
              {
                coding: '', // 产品编号
                name: '', // 产品名称
                items: [
                  {
                    number: undefined, // 销售数量
                    deliveryTime: undefined, // 交货时间
                    deliveryType: '1', // 交货方式
                    remark: '', // 备注
                    short: undefined, // 产品生产最短周期
                    earlyWarning: undefined, // 产品生产最短周期
                  },
                ],
              },
            ],
          },
          name: '交货要求',
          required: 2,
          span: 24,
          uuid: uniqueid(''),
          isMust: 1,
          isProcessConditions: 1,
          fieldName: 'contractNumber',
          values: [],
        },
        {
          name: '附件',
          code: 'FILE',
          componentType: 'FILE',
          props: { data: [] },
          required: 2,
          span: 12,
          uuid: '17',
          show: 1,
          values: [],
          sort: 15,
          isMust: 1,
          isProcessConditions: 2,
          fieldName: '',
        },
      ],
    };
  },

  actions: {},
});

export default useBuyStore;
